<?php
/**
 * Created by PhpStorm.
 * User: Liuhongchuan
 * Date: 2018/5/2
 * Time: 10:35
 * 临时借记卡管理
 */
namespace app\operation\controller;

use app\common\controller\OperationBase;

class WaterPump extends OperationBase {

	public function _initialize() {
		parent::_initialize();  
    }


	public function index(){
        $auth_group = sp_get_auth_menu_3("20061003");
        $shops = db("shop")->where(array("parent_id" => array("neq", 0)))->order("parent_id desc, shop_name desc")->column("id, shop_name");
        $this->assign("shops", $shops);
        $this->assign("menus", $auth_group);
        echo $this->fetch();
	}	
	
	/*卡列表数据*/
	public function ajaxIndex() {
	    $shop_id = input("shop_id/d");
	    $card_no = input("card_no/s");
        $draw = input("draw",0) + 1;//请求时间

        $where = array();
	    if (!empty($shop_id)) {
	        $where["p.shop_id"] = array("eq", $shop_id);
        }
        if (!empty($card_no)) {
	        $where["p.card_no"] = array("like", "%{$card_no}%");
        }
        $start = input("start/s");
        $end = input("end/s");

        if (empty($start)) {
            $start = date('Y-m-d') . " 00:00:00";
        } else {
            $start = $start . " 00:00:00";
        }
        if (empty($end)) {
            $end = date('Y-m-d') . " 23:59:59";
        }else{
            $end = $end . " 23:59:59";
        }
        if ($end < $start) {
            $this->error("起始时间不能大于结束时间");
        }
        $where["p.create_time"] = array("between time", array($start, $end));

        $total = db("water_pumb")->alias("p")->where($where)->count(1);
        $list = db("water_pumb")->alias("p")
            ->join("m_shop s", "s.id = p.shop_id", "left")
            ->field("p.*, s.shop_name")
            ->where($where)
            ->order($this->get_order())
            ->limit($this->get_limit())
            ->select();

        $data = array('pageData' => $list, 'total' => $total, "draw" => $draw);
        $this->ajax($data);

	}
}
